//
//  DB.m
//  LaoGanMa_v2
//
//  Created by liuchang on 14/12/19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DB.h"
#import <sqlite3.h>

static sqlite3 * dbPoint = nil;

@implementation DB

+ (sqlite3 *)openDB
{
    if (dbPoint) {
        return dbPoint;
    }
    NSFileManager * manager = [NSFileManager defaultManager];
    NSArray * pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * path = [pathArr firstObject];
    path = [NSString stringWithFormat:@"%@/%@", path, @"CommaDataBase.rdb"];
    if (![manager fileExistsAtPath:path]) {
        NSString * path = [pathArr firstObject];
        path = [NSString stringWithFormat:@"%@/%@", path, @"CommaDataBase.rdb"];
        NSString * source = [[NSBundle mainBundle] pathForResource:@"CommaDataBase" ofType:@"rdb"];
        [manager copyItemAtPath:source toPath:path error:nil];
    }
    sqlite3_open([path UTF8String], &dbPoint);
    return dbPoint;
}

@end
